package com.suru.dtp;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TimePicker;

@SuppressLint("InflateParams")
public class DateTimePicker {
	private final Activity activity;

	private AlertDialog alertDialog;
	private DatePicker datePicker;
	private TimePicker timePicker;
	private boolean buildFlag;

	public DateTimePicker(Activity activity) {
		this.activity = activity;
		this.buildFlag = false;
		if (activity == null) {
			throw new NullPointerException("activity should not be null");
		}
	}

	public void build() {
		buildFlag = true;
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		View inflate = activity.getLayoutInflater().inflate(R.layout.picker_layout, null);
		builder.setView(inflate);
		datePicker = (DatePicker) inflate.findViewById(R.id.datePicker);
		timePicker = (TimePicker) inflate.findViewById(R.id.timePicker);
		builder.setTitle("Select Date and Time");
		builder.setPositiveButton("Select", null);
		builder.setNegativeButton("Cancel", null);
		alertDialog = builder.create();
	}

	public void show() {
		if (buildFlag) {
			alertDialog.show();
		} else {
			throw new IllegalArgumentException("call build() before show.");
		}
	}

}
